#ifndef YCSB_C_MEMCACHED_DB_H_
#define YCSB_C_MEMCACHED_DB_H_
#include "../core/db.h"
#include <iostream>
#include <string>
#include "../core/properties.h"
#include "../memcached/libmemcached-1.0/memcached.h"

using std::cout;
using std::endl;

#define MAX_MEMC_CNT 256

namespace ycsbc {

class MemcachedDB:public DB{
    public:
        
        virtual void Init();
        MemcachedDB(std::string hsost, std::string port)
        {
            cfg_string = "--SERVER=" + hsost + ":" + port;
            cnt_ = 0;
        }
        ~MemcachedDB(){
            for (int i = 0; i < cnt_;i++)
                memcached_free(memc_[i]);
        }

        int Read(const std::string &table, const std::string &key,
           const std::vector<std::string> *fields,
           std::vector<KVPair> &result);

        int Scan(const std::string &table, const std::string &key,
           int len, const std::vector<std::string> *fields,
           std::vector<std::vector<KVPair>> &result) {
            throw "Scan: function not implemented!";
        }

        int Update(const std::string &table, const std::string &key,
             std::vector<KVPair> &values);

        int Insert(const std::string &table, const std::string &key,
             std::vector<KVPair> &values) {
            return Update(table, key, values);
        }

        int Delete(const std::string &table, const std::string &key);
    private:
        
        int cnt_;
        memcached_st *memc_[MAX_MEMC_CNT];
        std::string cfg_string;
};

}



#endif